package com.itchen.web.servlet;

import com.alibaba.fastjson.JSON;
import com.itchen.pojo.City;
import com.itchen.service.ProvinceService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

/**
 * @author げっしょく
 * @date 2021/9/6
 */
@WebServlet("/cityServlet")
public class CityServlet extends HttpServlet {
    private ProvinceService p = new ProvinceService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/json;charset=utf-8");

        String id = request.getParameter("id");
//        BufferedReader reader = request.getReader();
//        String s = reader.readLine();
        System.out.println(id);

        List<City> cities = p.selectCity(Integer.parseInt(id));

        String s1 = JSON.toJSONString(cities);
        response.getWriter().write(s1);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
